<template>
  <div class="topNavBox">
    <div>
      <span>123</span>
      <span>后台管理系统</span>
    </div>
    <div>
      <el-button @click="fullScreen()">全屏模式</el-button>
      <span>2</span>
      <div>
        <img src="../assets/images/bg_png.png" alt="">
        <el-dropdown trigger="click" @visible-change="visibleChange" @command="handleCommand">
          <span class="el-dropdown-link">
            <div class="userName">
              <span>admin</span>
              <span :class="[{triangle : !menuOpen, optriangle : menuOpen}]"></span>
            </div>1
<!--            <i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
          </span>

          <el-dropdown-menu slot="dropdown" @click.stop>
            <el-dropdown-item command="changeMessage">修改信息</el-dropdown-item>
            <el-dropdown-item command="logOut">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script>
import model from 'components/model.vue'

export default {
  data () {
    return {
      menuOpen: false
    }
  },
  components: {
    model
  },
  methods: {
    visibleChange (val) {
      this.menuOpen = val
    },

    fullScreen (el = document.body) {
      let isFullscreen = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen
      if (!isFullscreen) {
        (el.requestFullscreen && el.requestFullscreen()) ||
        (el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
        (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen())
      } else {
        document.exitFullscreen ? document.exitFullscreen() : document.mozCancelFullScreen ? document.mozCancelFullScreen() : document.webkitExitFullscreen ? document.webkitExitFullscreen() : ''
      }
    },

    changeMessage () {
      console.log('a')
    },

    logOut () {
      window.localStorage.clear()
      this.$nextTick(() => {
        this.$router.push({path: '/login'})
      })
    },

    handleCommand (command) {
      if (command === 'logOut') {
        this.logOut()
      } else {
        this.changeMessage()
      }
    }
  }
}
</script>

<style type="text/css" lang='scss' scoped>
  .topNavBox {
    display: flex;
    justify-content: space-between;
    height: 70px;
    line-height: 70px;
    background-color: #242f42;
    color: white;
    padding: 0 20px;
    div {
      display: flex;
      justify-content: space-between;
      img {
        width: 50px;
        margin: 0 10px;
      }
    }
  }
  .triangle {
    display: block;
    width: 0;
    height: 0;
    border: 8px solid;
    border-color: #ffffff transparent transparent transparent;
    margin-top: 33px;
    margin-left: 8px;
  }
  .optriangle {
    display: block;
    width: 0;
    height: 0;
    border: 8px solid;
    border-color: transparent transparent #ffffff transparent;
    margin-top: 25px;
    margin-left: 8px;
  }
  .el-dropdown {
    color: white;
  }
  .userName {
    cursor: pointer;
  }
</style>
